//
//  QCHomeRetweetView.swift
//  SwiftDemoWithSina
//
//  Created by qu on 2017/2/5.
//  Copyright © 2017年 Apple. All rights reserved.
//

import UIKit
import SnapKit

class QCHomeRetweetView: UIView {

    // 记录转发微博的底部约束
    var retweetViewBottomConstraint: Constraint?
    
    var statusViewModel: QCStatusViewModel?{
        didSet{
          contentLabel.text = statusViewModel?.homeModel?.retweeted_status?.text
          
            retweetViewBottomConstraint?.deactivate()
            
            if let picUrls = statusViewModel?.homeModel?.retweeted_status?.pic_urls, picUrls.count > 0 {
                pictureView.pic_urls = picUrls
                
                self.snp.makeConstraints({ (make) in
                    retweetViewBottomConstraint = make.bottom.equalTo(pictureView).offset(10).constraint
                    
                })
                pictureView.isHidden = false
                
            }else {
                self.snp.makeConstraints({ (make) in
                    retweetViewBottomConstraint = make.bottom.equalTo(contentLabel).offset(10).constraint
                })
                pictureView.isHidden = true
            }
            
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setupUI(){
        backgroundColor = RGB(r: 235, g: 235, b: 235)
        addSubview(contentLabel)
        addSubview(pictureView)
        contentLabel.snp.makeConstraints { (make) in
            make.left.top.equalToSuperview().offset(10)
            make.width.equalTo(KSCREENW - 20)
        }
        
        pictureView.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(10)
            make.top.equalTo(contentLabel.snp.bottom).offset(10)
        }
        snp.makeConstraints { (make) in
           retweetViewBottomConstraint = make.bottom.equalTo(pictureView).offset(10).constraint
        }
        
    }
    
    private lazy var contentLabel: UILabel = {
       let lab = UILabel(fontSize: QCNORMALFONTSIZE, textColor: UIColor.darkGray)
        lab.numberOfLines = 0
        return lab
        
    }()
    private lazy var pictureView: QCHomePictureView = {
       
        let view = QCHomePictureView()
        view.backgroundColor = self.backgroundColor
        return view
    }()

}
